//
//  HBJNetworkManager+Extensions.swift
//  zhihuifan
//
//  Created by apple on 2017/8/24.
//  Copyright © 2017年 youyou. All rights reserved.
//

import Foundation
//MARK:-首页
extension HBJNetworkManager{
    //推荐商家
    func loadRecommendStore(completion: @escaping (_ isSuccess:Bool,_ recommendList:[[String:AnyObject]]?)->()) {
        let urlstring = "welcome/getRecommended"
        let parameters = ["platform":"1","param":["cityCode":cityCode,"latitude":latitude,"longitude":longitude]] as [String : Any]
        request(url: urlstring,
                method: .post,
                paramters: parameters) { (json, isSuccess) in
                    if isSuccess {
                        guard let data = json?["data"],
                            let list = data["memList"] else{
                                completion(false, nil)
                                return
                        }
                        completion(true, list as! [[String:AnyObject]]?)
                        
                    }else{
                        completion(false,nil)
                    }

                    
        }
    }
    //热门商家
    func loadHotShop(completion:@escaping (_ isSuccess:Bool,_ hotShopList:[[String:AnyObject]]?)->()){
        let urlString = "welcome/hotShop"
        let parameters = ["platform":"1","param":["cityCode":cityCode,"latitude":latitude,"longitude":longitude]] as [String : Any]
        request(url: urlString, method: .post, paramters: parameters) { (json, isSuccess) in
            
            if isSuccess {
                guard let data = json?["data"],let memberList = data["memberPojoList"] as? [[String:AnyObject]] else{
                    return
                }
                completion(true, memberList)
               // completion(true, json)
            }else{
                completion(false, nil)
            }
        }
    }
    //首页分类
    func loadCategory(completion:(_ isSucess:Bool,_ cateGoryList:[[String:String]]?) -> ()){
        let urlString = "welcome/hotShop"
        let parameters = ["platform":"1","param":["cityCode":cityCode,"latitude":latitude,"longitude":longitude]] as [String : AnyObject]
        tokenRequest(url: urlString, method: .post, paramters: parameters) { (cateList, isSuccess) in
            
        }
    }
}
